<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
include("feedwriter/feed.php");
class Webservice extends CI_Controller {
	
	var $data;	
	var $settings;
    var $community;
	
	public function __construct()
	{
		parent::__construct();
		$this->load->model('data_fetcher');
		$this->load->helper('text');
	}
	
	public function index()
	{
		//$this->load_player('digradio');		
	}
   
    public function get_communty_feeds($community)
    {
        $feeds = $this->data_fetcher->fetch_community_feeds($community);
        $data = array();
        $json = array();
        foreach($feeds as $feed)
        {
            $feed['ct-strContent'] = strip_tags($feed['ct-strContent'],'<img><p>');
            $data[] = $feed;
        }
        $json["feeds"] = $data;
        echo json_encode($json);
        
    }
    
    public function get_content_by_type($type,$community,$limit=10,$offset=0)
    {
            
        $this->community = $this->data_fetcher->fetch_community_data($community);
        $feeds = $this->data_fetcher->fetch_content_type_archive($type,$this->community->intID,$limit,$offset);
        $data = array();
    
        foreach($feeds as $feed)
        {
            $feed['ct-strContent'] = strip_tags($feed['ct-strContent'],'<img><p>');
            $data[] = $feed;
        }
        echo json_encode($data);
        
    }
    
    public function rss_feed()
    {
        // creating rss feed with our most recent 20 posts in variable $post

        $feeds = $this->data_fetcher->fetch_news();    
        // create new instance
        $feed = new Feed();
    
        // set your feed's title, description, link, pubdate and language
        $feed->title = 'Pinoytuner';
        $feed->description = 'Pinoytuner news feeds';
        $feed->link = 'http://pinoytuner.com';
        $feed->lang = 'en';
        $feed->pubdate = "10-22-2013"; // date of your last update (in this example create date of your latest post)
    
        // add posts to the feed
        foreach($feeds as $f){
        // set item's title, author, url, pubdate and description
            $community = $this->data_fetcher->get_community_name($f['fk-tb_mas_community']);
            $type = $this->data_fetcher->get_type_name($f['fk-tb_mas_content_types']);
            $simplified = simplify_title($f['strTitle']);
            
            $feed->add($f['strTitle'], $f['strAuthor'], base_url().$community."/content/".$type."/".$f['intID']."/".$simplified, $f['dteStart'], $f['strSecondary'],$f['ct-strYahooContent'],$f['strPicture']);
        }
        
        // show your feed (options: 'atom' (recommended) or 'rss')
        $feed->render('rss');
        
        
    }
    
    
  
	

}